package game.module.club.dao;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author:Pomelo.lee
 * @date:2017年9月20日 下午7:01:02
 */
public class ClubRoomCache {

	private static Logger logger = LoggerFactory.getLogger(ClubRoomCache.class);

	static class SingletonHolder {
		static ClubRoomCache instance = new ClubRoomCache();
	}

	public static ClubRoomCache getInstance() {
		return SingletonHolder.instance;
	}

	/**
	 * 俱乐部房间
	 */
	private static Map<Integer, Map<String, Byte>> club_room = new ConcurrentHashMap<>();

	private static Map<String, Integer> club_room_playerid = new ConcurrentHashMap<>();

	public void addClubRoom(int clubId, String roomId, byte roomType) {
		if (!club_room.containsKey(clubId)) {
			club_room.put(clubId, new ConcurrentHashMap<>());
		}
		club_room.get(clubId).put(roomId, roomType);
		club_room_playerid.put(roomId, clubId);
	}

	public void removeClubRoom(String roomId) {
		Integer clubId = club_room_playerid.get(roomId);
		if (clubId == null) {
			logger.error("not found clubRoom roomId={}", roomId);
			return;
		}
		Map<String, Byte> clubRoomMap = club_room.get(clubId);
		if (clubRoomMap != null) {
			logger.error("not found clubRoom roomId={},clubId={}", roomId, clubId);
			clubRoomMap.remove(roomId);
		}
	}

	/**
	 * 列出俱乐部房间组
	 * 
	 * @param clubId
	 * @return
	 */
	public Map<String, Byte> listClubRoomByClubId(int clubId) {
		return club_room.get(clubId);
	}

}
